<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\Users;

/* @var $this yii\web\View */
/* @var $searchModel app\models\QaSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '文章管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="qa-index">

    <h3><?php echo Html::encode($this->title) ?></h3>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?php
    echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            //['class' => 'yii\grid\SerialColumn'],不需要显示前面的导航
            [
                'attribute' => 'id',
                'headerOptions' => ['width' => '100']
            ],
            [
                'attribute' => 'uid',
                'label' => '用户ID',
                'value' => function($model) {
                    $user = Users::findOne(['id' => $model->uid]);
                    return '[' . $user->id . ']' . $user->username;
                },
                        'headerOptions' => ['width' => '200']
                    ],
                    'title',
                    [
                        'attribute' => 'status',
                        'label' => '状态',
                        'value' => function($model) {
                            return $model->status == 1 ? "活跃" : "锁定";
                        },
                        'headerOptions' => ['width' => '100']
                    ],
                    ['class' => 'yii\grid\ActionColumn', 'header' => '操作', 'template' => '{view} {update} {delete}',
                        'buttons' => [
                            'view' => function ($url, $model) {
                                $url = "/article/view?id=" . $model->id;
                                return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, ['title' => '查看', 'target' => '_blank']);
                            },
                                    'update' => function ($url, $model) {
                                return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, ['title' => '编辑', 'target' => '_blank']);
                            },
                                ],
                                'headerOptions' => ['width' => '70']
                            ],
                        ],
                        'emptyText' => '没有筛选到任何内容哦',
                    ]);
                    ?>

</div>
